﻿using AutoMapper;
using MaterialTypeRecognition.Shell.AuthenticationServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace MaterialTypeRecognition.Shell.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class AuthenticateController : ControllerBase
    {
        public AuthenticateController(IUserAuthenticationService userAuthentication, IMapper mapper)
        {
            _userAuthentication = userAuthentication;
            _mapper = mapper;
        }

        private readonly IMapper _mapper;

        private readonly IUserAuthenticationService _userAuthentication;

        [HttpPost]
        public async Task<AuthenticationResult> AuthenticateUser(UserModel userModel)
        {
            var dto = _mapper.Map<UserModelDto>(userModel);
            var model = await _userAuthentication.TryAuthenticateAsync(dto);

            return _mapper.Map<AuthenticationResult>(model);
        }

        [HttpGet]
        [Authorize(Policy = UserPermissoins.Users.OPN)]
        public void OPNAuthenticate()
        {
            // 仅用做认证接口。
        }

        [HttpGet]
        [Authorize(Policy = UserPermissoins.Users.OPNMonitor)]
        public void OPNMonitorAuthenticate()
        {
            // 仅用做认证接口。
        }

        [HttpGet]
        [Authorize(Policy = UserPermissoins.Users.ME)]
        public void MEAuthenticate()
        {
            // 仅用做认证接口。
        }

        [HttpGet]
        [Authorize(Policy = UserPermissoins.Users.PE)]
        public void PEAuthenticate()
        {
            // 仅用做认证接口。
        }

        [HttpGet]
        [Authorize(Policy = UserPermissoins.Users.Admin)]
        public void AdminAuthenticate()
        {
            // 仅用做认证接口。
        }
    }
}
